<?
function isCharField($type) {
	switch ($type) {
		case "char":
		case "nchar":
		case "text":
		case "longtext":
		case "ntext":
		case "smalltext":
		case "varchar":
		case "nvarchar":
			return true;
		
		default:
			return false;
	}
}

function isTextField($type) {
	switch ($type) {
		case "text":
		case "ntext":
			return true;
		
		default:
			return false;
	}
}

function isLongTextField($type) {
	switch ($type) {
		case "longtext":
		case "nlongtext":
			return true;
		
		default:
			return false;
	}
}


function isNumericField($type) {
	switch ($type) {
		case "int":
		case "numeric":
		case "money":
		case "decimal":
		case "float":
			return true;
		
		default:
			return false;
	}
}


function isBoolField($type) {
	switch ($type) {
		case "bit":
		case "tinyint":
			return true;
		
		default:
			return false;
	}
}


function isDateField($type) {
	switch ($type) {
		case "date":
		case "datetime":
			return true;
		
		default:
			return false;
	}
}


function renderField($f) {
	global $fields_prefix;
	
	$field = $f->name;
	$len = $f->max_length;
	$form = "<tr>
	<td align=\"right\" nowrap>
		$f->name <span class=\"mx-required\">*</span> : 
	</td>
	<td>
		";

	
	if (isBoolField($f->type))
		$form .= "<input type=\"checkbox\" name=\"$fields_prefix$field\" id=\"$fields_prefix$field\" value=\"1\" <?=\$$fields_prefix$field===\"1\"?\"checked\":\"\"?>>\n";
	elseif (isTextField($f->type) || isLongTextField($f->type))
		$form .= "<textarea name=\"$fields_prefix$field\" id=\"$fields_prefix$field\"><?=\$$fields_prefix$field?></textarea>\n";
	elseif (isCharField($f->type))
		$form .= "<input type=\"text\" name=\"$fields_prefix$field\" id=\"$fields_prefix$field\" value=\"<?=\$$fields_prefix$field?>\" size=\"".($len>50?50:$len)."\" maxlength=\"$len\">\n";
	elseif (isNumericField($f->type))
		$form .= "<input type=\"text\" name=\"$fields_prefix$field\" id=\"$fields_prefix$field\" value=\"<?=\$$fields_prefix$field?>\" size=\"".(10)."\" maxlength=\"$len\">\n";
	elseif (isDateField($f->type))
		$form .= "<input type=\"text\" name=\"$fields_prefix$field\" id=\"$fields_prefix$field\" value=\"<?=\$$fields_prefix$field?>\" size=\"".(10)."\" maxlength=\"10\">\n";

	$form .= '	</td>
</tr>
';
	return $form;
}
?>